import parole
from parole.colornames import colors
from parole.display import interpolateRGB
import pygame, random

import sim, main, sim_items, sim_creatures
from util import *

class PainPotion(sim_items.Potion):
    def __init__(self):
        sim_items.Potion.__init__(self, "pain", "!",
                ('life', 'less'),
                idDescription="A staple in any despot's torture chamber, "\
                    "this horrific brew rots away the innards slowly and "\
                    "methodically.")
        self.splashedCreatures = []
        self.thrower = None

        self.killText = \
"""
{\Gold Look Before You Leap!}

As the flask falls from your hand, you double over and clutch your stomach.
Agonizing pain shoots through your entire system and you vomit a torrent of
blood. Whatever was in that potion, it's eating you alive from the inside. All
that is left of a promising adventuring career is a crumpled corpse drenched in
its own blood. With any luck someone will find your body to give you a proper
burial... but don't get your hopes up.
""".strip()
        
    def quaff(self, quaffer):
        main.schedule.sendNow(sim.Event('decrease stat', main.schedule.time,
            (quaffer, 'hp', random.randint(10,30)), dests=[quaffer]))
        main.transient('Ouch, quaffing that really hurt!')
        quaffer.identify(self)
        quaffer.lastDamageSource = self

    def listen(self, event):
        super(PainPotion, self).listen(event)

        if event.id == 'fly':
            item, srcPos, destPos, trajectory = event.args
            if item is self:
                self.thrower = trajectory.liableParty

        elif event.id == 'splash':
            puddle, pos, map = event.args
            if isinstance(puddle, sim_items.PotionPuddle) and \
                    puddle.srcPotion is self:
                # someplace got splashed by us, so do some damage
                for obj in map[pos]:
                    if isinstance(obj, sim_creatures.Creature) and obj.feelsPain:
                        main.schedule.add(sim.Event("receive damage",
                            main.schedule.time, (obj, self.thrower, None,
                                3*puddle.amount), dests=[obj]))
                        if visible(obj) and obj not in self.splashedCreatures:
                            main.player.identify(self)
                            main.transient('%s writhes in pain as it is '
                                    'splashed by the strange liquid.' %\
                                       obj.noun(definite=1, capitalized=1), pos)
                        self.splashedCreatures.append(obj)
                                

#========================================
thingClass = PainPotion


